package org.iks.common.util;

import org.springframework.util.StopWatch;

import java.util.UUID;

/**
 * Author kzou
 * Date 2024/5/25
 * Description:
 */
public class StopWatchUtil {
    public static ThreadLocal<StopWatch> CURRENT_STOP_WATCH = new ThreadLocal<>();

    public static StopWatch stopWatch() {
        String uuid = UUID.randomUUID().toString();
        return stopWatch(uuid);
    }

    public static StopWatch stopWatch(String id) {
        if (CURRENT_STOP_WATCH.get() == null) {
            StopWatch stopWatch = new StopWatch(id);
            CURRENT_STOP_WATCH.set(stopWatch);
        }
        return CURRENT_STOP_WATCH.get();
    }

    public static void clearStopWatch() {
        CURRENT_STOP_WATCH.remove();
    }


}
